package com.scgl.sheet.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.scgl.sheet.domain.ScglDamage;
import com.scgl.sheet.service.IScglDamageService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 生产信息Controller
 *
 * @author ruoyi
 * @date 2024-10-30
 */
@RestController
@RequestMapping("/damage")
public class ScglDamageController extends BaseController
{
    @Autowired
    private IScglDamageService scglDamageService;

    /**
     * 查询生产信息列表
     */
    @RequiresPermissions("sheet:damage:list")
    @GetMapping("/list")
    public TableDataInfo list(ScglDamage scglDamage)
    {
        startPage();
        List<ScglDamage> list = scglDamageService.selectScglDamageList(scglDamage);
        return getDataTable(list);
    }

    /**
     * 导出生产信息列表
     */
    @RequiresPermissions("sheet:damage:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScglDamage scglDamage)
    {
        List<ScglDamage> list = scglDamageService.selectScglDamageList(scglDamage);
        ExcelUtil<ScglDamage> util = new ExcelUtil<ScglDamage>(ScglDamage.class);
        util.exportExcel(response, list, "生产信息数据");
    }

    /**
     * 获取生产信息详细信息
     */
    @RequiresPermissions("sheet:damage:query")
    @GetMapping(value = "/{optionId}")
    public AjaxResult getInfo(@PathVariable("optionId") Long optionId)
    {
        return success(scglDamageService.selectScglDamageByOptionId(optionId));
    }

    /**
     * 新增生产信息
     */
    @RequiresPermissions("sheet:damage:add")
    @Log(title = "生产信息新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScglDamage scglDamage)
    {
        return toAjax(scglDamageService.insertScglDamage(scglDamage));
    }

    /**
     * 修改生产信息
     */
    @RequiresPermissions("sheet:damage:edit")
    @Log(title = "生产信息修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScglDamage scglDamage)
    {
        return toAjax(scglDamageService.updateScglDamage(scglDamage));
    }

    /**
     * 删除生产信息
     */
    @RequiresPermissions("sheet:damage:remove")
    @Log(title = "生产信息删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{optionIds}")
    public AjaxResult remove(@PathVariable Long[] optionIds)
    {
        return toAjax(scglDamageService.deleteScglDamageByOptionIds(optionIds));
    }
}
